<template>
  <div class="adoptImageText">
    <y-rich-text
      v-model="content"
      :disabled="isView"
      :business-sys-module-code="businessSysModuleCode"></y-rich-text>
  </div>
</template>

<script>
export default {
  name: "adoptImageText",
  props: {
    adoptId: String,
    isView:{
      type: Boolean,
      default: false
    }
  },
  data(){
    return{
      id: '',
      content: '',
      businessSysModuleCode: 'ADOPT_IMAGE_TEXT',
    }
  },
  mounted(){
    this.$yAxios({
      url: this.$api.adopt.selectAdoptImageText,
      data:{
        adoptId: this.adoptId
      },
      loading: true
    }, info => {
      if(info){
        this.id = info.id;
        this.content = info.content || '';
      }
    })
  },
  methods:{
    async save(){
      return new Promise(resolve => {
        if(!this.content){
          this.$alert('请编辑商品详情', {
            confirmButtonText: '确定'
          });
          resolve(false);
          return;
        }
        let url = this.$api.adopt.saveAdoptImageText
        let data = {
          content: this.content,
          adoptId: this.adoptId
        }
        if(this.id){
          data.id = this.id
        }
        this.$yAxios({
          url,
          data,
          loading: true
        }, info => {
          this.$message({
            type: 'success',
            message: '保存商品详情成功'
          });
          resolve(info);
        })
      })
    }
  },
}
</script>

<style scoped lang="less">
.adoptImageText{
  height: 100%;
  overflow: hidden;
  /deep/ .YRichTextBlock{
    height: 100%;
    .quill-editor{
      height: 100%;
      >.ql-container{
        height: calc(100% - 42px);
      }
    }
  }
}
</style>